<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('售卖机物品信息列表')" />
    <th:block th:include="include :: select2-css"/>

</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>归属码商：</p>
                                <select name="userId" id="userId" class="form-control"
                                        th:with="type=${@sysUser.selectUserListByType('ms')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.userName}"
                                            th:value="${dict.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <p>是否占用：</p>
                                <select name="goodStatus" th:with="type=${@dict.getType('yes_or_no')}" class="form-control">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:smjGoodList:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:smjGoodList:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:smjGoodList:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:smjGoodList:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js"/>

     <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:smjGoodList:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:smjGoodList:remove')}]];
        var idDatas = [[${@dict.getType('null')}]];
        var realChannelCodeDatas = [[${@dict.getType('null')}]];
        var machineIdDatas = [[${@dict.getType('null')}]];
        var goodStatusDatas = [[${@dict.getType('null')}]];
        var goodHdDatas = [[${@dict.getType('null')}]];
        var goodUrlDatas = [[${@dict.getType('null')}]];
        var goodPriceDatas = [[${@dict.getType('null')}]];
        var goodNumDatas = [[${@dict.getType('null')}]];
        var createTimeDatas = [[${@dict.getType('null')}]];
        var updateTimeDatas = [[${@dict.getType('null')}]];
        var createUserDatas = [[${@dict.getType('null')}]];
        var updateUserDatas = [[${@dict.getType('null')}]];
        var prefix = ctx + "business/smjGoodList";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "售卖机物品信息",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id',
                    title : 'null',
                    visible: false
                },
                {
                    field : 'userName',
                    title : '归属码商'
                },
                {
                    field : 'realChannelCode',
                    title : '实际通道编码'
                },
                {
                    field : 'machineId',
                    title : '归属机器编码'
                },
                {
                    field : 'goodStatus',
                    title : '是否占用',
                    formatter: function (value, row, index) {
                        if (row.goodStatus == 0) {
                            return "否"
                        }else{
                            return "是"
                        }


                        //return statusTools(row);
                    }
                },
                {
                    field : 'goodHd',
                    title : '物品货道'
                },
                {
                    field : 'goodUrl',
                    title : '物品链接'
                },
                {
                    field : 'goodPrice',
                    title : '物品价格'
                },
                {
                    field : 'goodNum',
                    title : '物品剩余数量'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function statusTools(row) {
            if (row.goodStatus == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }
        function disable(userId) {
            $.operate.post(prefix + "/changeStatus", { "id": userId, "goodStatus": 0 });
        }

        /* 用户管理启用 */
        function enable(userId) {
            $.operate.post(prefix + "/changeStatus", { "id": userId, "goodStatus": 1 });
        }
    </script>
</body>
</html>
